package main

import (
	"fmt"
	"time"
)

func test2() {
	ch1 := make(chan string)
	ch2 := make(chan string)

	// goroutine 1: 2 秒后发消息
	go func() {
		time.Sleep(2 * time.Second)
		ch1 <- "来自 ch1 的消息"
	}()

	// goroutine 2: 1 秒后发消息
	go func() {
		time.Sleep(1 * time.Second)
		ch2 <- "来自 ch2 的消息"
	}()

	time.Sleep(3 * time.Second)
	select {
	case msg := <-ch1:
		fmt.Println("收到：", msg)
	case msg := <-ch2:
		fmt.Println("收到：", msg)
	default:
		fmt.Println("两个都没消息")
	}
}
